package org.cdc.divination.frame.parents;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class AbstractCommandExecutor implements CommandExecutor, TabCompleter {
    private Map<String, Method> commandMethods;
    public void initExecutor(){
        final AtomicInteger size =new AtomicInteger(0);
        Arrays.stream(this.getClass().getMethods()).forEach(a->{
            //如果没有command注解那么就跳过
            if (!a.isAnnotationPresent(org.cdc.divination.frame.annotation.Command.class)) return;
            org.cdc.divination.frame.annotation.Command command = a.getAnnotation(org.cdc.divination.frame.annotation.Command.class);
            //得到模板的所有参数长度
           if (size.get() < command.commandModel().split("\\s").length) size.set(command.commandModel().split("\\s").length);
            commandMethods.put(command.commandModel(),a);
        });
    }
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        return false;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        return null;
    }
}
